package com.ruoyi.be.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.be.domain.MedicalCpoeSickroom;
import com.ruoyi.be.service.IMedicalCpoeSickroomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病房记录Controller
 * 
 * @author ruoyi
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/be/sickroom")
public class MedicalCpoeSickroomController extends BaseController
{
    @Autowired
   private IMedicalCpoeSickroomService medicalCpoeSickroomService;



    /**
     * 查询病房记录列表
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalCpoeSickroom medicalCpoeSickroom)
    {
        startPage();
        List<MedicalCpoeSickroom> list = medicalCpoeSickroomService.selectMedicalCpoeSickroomList(medicalCpoeSickroom);
        return getDataTable(list);
    }

    /**
     * 查询病房记录列表
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:query')")
    @GetMapping("/query")
    public TableDataInfo query(String areaname)
    {
        System.out.println(areaname);
        startPage();
        List<MedicalCpoeSickroom> list = medicalCpoeSickroomService.selectMedicalCpoeSickroomListBySiftName(areaname);
        return getDataTable(list);
    }

    /**
     * 查询病房记录列表（床位没装满的房间）
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:list')")
    @GetMapping("/listSift")
    public TableDataInfo listBySift()
    {
        List<MedicalCpoeSickroom> list = medicalCpoeSickroomService.selectMedicalCpoeSickroomListBySift();
        return getDataTable(list);
    }

    /**
     * 导出病房记录列表
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:export')")
    @Log(title = "病房记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalCpoeSickroom medicalCpoeSickroom)
    {
        List<MedicalCpoeSickroom> list = medicalCpoeSickroomService.selectMedicalCpoeSickroomList(medicalCpoeSickroom);
        ExcelUtil<MedicalCpoeSickroom> util = new ExcelUtil<MedicalCpoeSickroom>(MedicalCpoeSickroom.class);
        util.exportExcel(response, list, "病房记录数据");
    }

    /**
     * 获取病房记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:query')")
    @GetMapping(value = "/room/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(medicalCpoeSickroomService.selectMedicalCpoeSickroomById(id));
    }
    /**
     * 获取病房记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:query')")
    @GetMapping(value = "/{areaname}")
    public AjaxResult getbf(@PathVariable("areaname") String areaname)
    {
        return AjaxResult.success(medicalCpoeSickroomService.selectMedicalCpoeSickroomByareaname(areaname));
    }

    /**
     * 新增病房记录
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:add')")
    @Log(title = "病房记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalCpoeSickroom medicalCpoeSickroom)
    {
        medicalCpoeSickroom.setId(SecurityUtils.getUsername()+new Date().getTime());
        return toAjax(medicalCpoeSickroomService.insertMedicalCpoeSickroom(medicalCpoeSickroom));
    }

    /**
     * 修改病房记录
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:edit')")
    @Log(title = "病房记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalCpoeSickroom medicalCpoeSickroom)
    {
        return toAjax(medicalCpoeSickroomService.updateMedicalCpoeSickroom(medicalCpoeSickroom));
    }

    /**
     * 删除病房记录
     */
    @PreAuthorize("@ss.hasPermi('be:sickroom:remove')")
    @Log(title = "病房记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(medicalCpoeSickroomService.deleteMedicalCpoeSickroomByIds(ids));
    }
}
